package com.martin.dsc.mine;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class OrderManager extends Order{
    // 单例实例
    private static final OrderManager ORDER_MANAGER = new OrderManager();
    // 订单存储
    private final ConcurrentHashMap<String,Order> orderMap = new ConcurrentHashMap<>();

    private OrderManager() { }

    public static OrderManager getInstance() {
        return ORDER_MANAGER;
    }

    // 创建订单并存储
    public void createOrder(  Order order) {
        if (order != null && order.getOrderId() != null) {
            orderMap.put(order.getOrderId(), order);
        }
    }

    // 获取所有订单
    public List<  Order> getAllOrders() {
        return Collections.unmodifiableList(new ArrayList<>(orderMap.values()));
    }

    // 根据订单号获取订单
    public   Order getOrderById(String orderId) {
        return orderMap.get(orderId);
    }

}
